package tech.aistar.mapper;


import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.security.core.parameters.P;
import tech.aistar.entity.Collections;

import java.util.List;

public interface CollectionsMapper {

    //根据id获取收藏明细()
    @Select("select count(*) from collections where id = #{value}")
    Integer findById(Integer id);

    //根据id查找出该用户收藏的商品
    @Select("select * from collections where id =#{value} and type=3 and collect_status=0")
    List<Collections> findByGood(Integer id);

    //根据id查找出该用户收藏的帖子
    @Select("select * from collections where id =#{value} and type=1 and collect_status=0")
    List<Collections> findByPost(Integer id);

    //根据id查找出该用户收藏的新闻
    @Select("select * from collections where id =#{value} and type=2 and collect_status=0")
    List<Collections> findByNews(Integer id);

    //取消商品
    @Update("update collections set collect_status = 1 where id = #{id} and kind_id = #{kindId} and type = 3")
    void delGoods(@Param("id") Integer id,@Param("kindId")Integer kindId);

    @Update("update collections set collect_status = 1 where id = #{id} and kind_id = #{kindId} and type = 1")
    void delPosts(@Param("id") Integer id,@Param("kindId")Integer kindId);

    //添加商品收藏
    @Insert("insert into collections(id,collect_time,kind_id,type,collect_status) values(#{id},now(),#{kindId},3,0)")
    void addGoods(@Param("id")Integer id, @Param("kindId")Integer kindId);

    //添加帖子收藏
    @Insert("insert into collections(id,collect_time,kind_id,type,collect_status) values(#{id},now(),#{kindId},1,0)")
    void addPosts(@Param("id")Integer id, @Param("kindId")Integer kindId);

    //添加新闻收藏
    @Insert("insert into collections(id,collect_time,kind_id,type,collect_status) values(#{id},now(),#{kindId},2,0)")
    void addNews(@Param("id")Integer id, @Param("kindId")Integer kindId);

}
